package gui;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import domein.Webinar;
import java.awt.Color;
import java.awt.Image;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.border.EtchedBorder;

/**
 *
 * @author Robin
 */
public class WebinarCellRenderer extends JLabel implements ListCellRenderer {

    public WebinarCellRenderer() {
        setOpaque(false);

        setIconTextGap(12);
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        Webinar w = (Webinar) value;

        setText("<html>" + w.getOnderwerp() + "<br>" + w.getDag().toString() + "</html>");


        ImageIcon ico = new ImageIcon(w.getAfbeelding());
        ImageIcon tmpIcon = new ImageIcon(w.getAfbeelding());

        if (tmpIcon != null) {
            if (tmpIcon.getIconWidth() > 75) {
                ico = new ImageIcon(tmpIcon.getImage().getScaledInstance(75, -1, Image.SCALE_DEFAULT));
            } else { //no need to miniaturize
                ico = new ImageIcon(tmpIcon.getImage().getScaledInstance(75, -1, Image.SCALE_DEFAULT));
            }
        }

        setIcon(ico);
        setHorizontalAlignment(CENTER);
        setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        setVerticalAlignment(CENTER);

        if (isSelected) {
            setForeground(Color.lightGray);

        } else {
            setForeground(Color.black);

        }

        return this;
    }
}
